﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace Zero.UControl.Assets.Converter
{
    public class Bool2Visibility : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value == null) return Visibility.Collapsed;

            bool flag = bool.Parse(value.ToString());
            if (parameter != null)
            {
                if (!bool.TryParse(parameter.ToString(), out bool flag2))
                    throw new Exception("传入的类型必须是bool类型");
                return flag == flag2 ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                return flag ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility val = (Visibility)value;
            return val == Visibility.Visible;
        }
    }
}
